﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace timetableasy.Models
{
    public class CourseProgramRepository
    {
        private TimeTableDBDataContext db = new TimeTableDBDataContext();

        //Query Methods
        public IQueryable<CourseProgram> FindAllCoursePrograms()
        {
            return db.CoursePrograms;
        }

        public CourseProgram GetCourseProgramById(int id)
        {
            return db.CoursePrograms.SingleOrDefault(cp => cp.CourseProgramId == id);
        }

        //Insert/Delete Methods

        public void Add(CourseProgram courseProgram)
        {
            db.CoursePrograms.InsertOnSubmit(courseProgram);
        }

        public void Delete(CourseProgram courseProgram)
        {
            db.CoursePrograms.DeleteOnSubmit(courseProgram);
        }

        //Persistence

        public void Save()
        {
            db.SubmitChanges();
        }
    }
}